package com.atguigu.jobs;


import com.atguigu.constant.RedisConstant;
import com.atguigu.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Set;

@Component("appJob")
public class ClearImageJob {

    @Autowired
    private JedisPool jedisPool;

    public void clearImage(){
        Jedis jedis= jedisPool.getResource();
        Set<String> pictures = jedis.sdiff(RedisConstant.SETMEAL_PIC_RESOURCES,RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        for (String picture : pictures) {
//1.在七牛云删除图片
            QiniuUtils.deleteFileFromQiniu(picture);
            //2.在redis对应的集合中删除垃圾图片名称
            jedis.srem(RedisConstant.SETMEAL_PIC_DB_RESOURCES,picture);

        }
        jedis.close();
    }

}
